<?php
include "../db/sql.php";
$id = $_POST['user_id'];
$pw = $_POST['user_pw'];
$OK_in = false;
$from = $db->query("SELECT Account, Password,RealName from Base_User ");
while ($row = $from->fetch()) {
    if ($row['Account'] == $id && $row['Password'] == $pw) {
        $OK_in = true;
        $_SESSION['name'] = $row['RealName'];
        $_SESSION['id'] = $row['Account'];
    }
}
if ($OK_in) {
    setcookie('is_login','1',0,'/');
    setcookie('user_id',$id,0,'/');
    echo "ok".PHP_EOL;
    echo "<script>window.location.href='../index.php';</script>";
} else {
    setcookie('is_login','0',0,'/');
    setcookie('user_id',false);
    echo "<div id='login_info'><i class='far fa-question-circle'></i> 姓名或密码错误，请重新输入</div>";
}
?>